<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script>
        function fun() {
            var xmlhttp;

            // 1.创建核心对象
            if (window.XMLHttpRequest){
                xmlhttp=new XMLHttpRequest()
            } else {
                xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
            }

            // 建立连接
            xmlhttp.open("GET","/ajaxServlet?username=tom",true)

            // 发送请求
            xmlhttp.send()

            xmlhttp.onreadystatechange=function () {
                if (xmlhttp.readyState==4 && xmlhttp.status==200){
                    let responseText = xmlhttp.responseText;
                    console.log(responseText)
                }
            }
        }
    </script>
</head>
<body>
<input type="button" value="发送异步请求" onclick="fun();">
</body>
</html>